﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Nyamr
{
    public class IndexItem
    {
        public string Key { get; set; }
        public string ValueFileName { get; set; }

        public void Write(StreamWriter writer)
        {
            writer.WriteLine(Key);
            writer.WriteLine(ValueFileName);
            writer.Flush();
        }

        public static IndexItem Read(StreamReader reader)
        {
            var node = new IndexItem();
            node.Key = reader.ReadLine();
            node.ValueFileName = reader.ReadLine();
            return node;
        }

        public static void Save(string path, List<IndexItem> data)
        {
            var writer = new StreamWriter(path);
            foreach (var item in data)
            {
                item.Write(writer);
            }
            writer.Close();
        }

        public static List<IndexItem> Load(string path)
        {
            var result = new List<IndexItem>();
            var reader = new StreamReader(path);
            while (!reader.EndOfStream)
            {
                result.Add(Read(reader));
            }
            reader.Close();
            return result;
        }
    }
}
